import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  // 登录页面
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  // 404 页面
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/Dashboard/index'),
      meta: { title: '工作台', icon: 'gongzuotai' }
    }]
  },
  // 新增订单
  {
    path: '/warehouse/details/null/',
    component: Layout,
    hidden: true,
    children: [{
      path: '',
      name: 'warehouse',
      component: () => import('@/components/addhouseList/index'),
      meta: { title: '新增仓库', activeMenu: '/employee' }
    }]
  },
  // 基础信息管理
  {
    path: '/task',
    component: Layout,
    redirect: '/task/ckgl',
    meta: { title: '基础信息管理', icon: 'jichuxinxi' },
    children: [{
      path: 'ckgl',
      name: 'ckgl',
      component: () => import('@/views/jcxxgl/ckgl.vue'),
      meta: { title: '仓库管理', icon: '点捕捉节点' }
    },
    {
      path: 'kqgl',
      name: 'kqgl',
      component: () => import('@/views/jcxxgl/kqgl.vue'),
      meta: { title: '库位管理', icon: '点捕捉节点' }
    },
    {
      path: 'kwgl',
      name: 'kwgl',
      component: () => import('@/views/jcxxgl/kwgl.vue'),
      meta: { title: '库位管理', icon: '点捕捉节点' }
    }, {
      path: 'kwst',
      name: 'kwst',
      component: () => import('@/views/jcxxgl/kwst.vue'),
      meta: { title: '库位视图', icon: '点捕捉节点' }
    },
    {
      path: 'hpgl',
      name: 'hpgl',
      component: () => import('@/views/jcxxgl/hpgl.vue'),
      meta: { title: '货品管理', icon: '点捕捉节点' }
    },
    {
      path: 'hplxgl',
      name: 'hplxgl',
      component: () => import('@/views/jcxxgl/hplxgl.vue'),
      meta: { title: '货品类型管理', icon: '点捕捉节点' }
    }
    ]
  },
  // 商务管理
  {
    path: '/hzgl',
    component: Layout,
    redirect: '/hzgl',
    meta: { title: '商务管理', icon: 'shangwu' },
    children: [{
      path: 'hzgl',
      name: 'hzgl',
      component: () => import('@/views/shangwuGl/hzgl'),
      meta: { title: '仓库管理', icon: '点捕捉节点' }
    },
    {
      path: 'cysgl',
      name: 'cysgl',
      component: () => import('@/views/shangwuGl/cysgl'),
      meta: { title: '库位管理', icon: '点捕捉节点' }
    }
    ]
  },
  // 库内管理
  {
    path: '/kngl',
    component: Layout,
    redirect: '/kngl/pdd',
    meta: { title: '库内管理', icon: 'ico_yaokuguanli_kucunchaxun' },
    children: [{
      path: 'pdd',
      name: 'pdd',
      component: () => import('@/views/kngl/pdd.vue'),
      meta: { title: '盘点单', icon: '点捕捉节点' }
    },
    {
      path: 'pdrw',
      name: 'pdrw',
      component: () => import('@/views/kngl/pdrw.vue'),
      meta: { title: '盘点任务', icon: '点捕捉节点' }
    },
    {
      path: 'kcsy',
      name: 'kcsy',
      component: () => import('@/views/kngl/kcsy.vue'),
      meta: { title: '库存损益', icon: '点捕捉节点' }
    },
    {
      path: 'sskc',
      name: 'sskc',
      component: () => import('@/views/kngl/sskc.vue'),
      meta: { title: '实时库存', icon: '点捕捉节点' }
    }
    ]
  },
  // 入库管理
  {
    path: '/rkgl',
    component: Layout,
    redirect: '/rkgl',
    meta: { title: '入库管理', icon: 'ico_kufangguanli_wupinruku' },
    children: [{
      path: 'rkd',
      name: 'rkd',
      component: () => import('@/views/rkgl/rkd'),
      meta: { title: '入库单', icon: '点捕捉节点' }
    },
    {
      path: 'shrw',
      name: 'shrw',
      component: () => import('@/views/rkgl/shrw'),
      meta: { title: '收货任务', icon: '点捕捉节点' }
    },
    {
      path: 'sjrw',
      name: 'sjrw',
      component: () => import('@/views/rkgl/sjrw'),
      meta: { title: '上架任务', icon: '点捕捉节点' }
    }
    ]
  },
  // 出库管理
  {
    path: '/ckgl',
    component: Layout,
    redirect: '/ckgl',
    meta: { title: '出库管理', icon: 'ico_kufangguanli_wupinchuku' },
    children: [{
      path: 'ckd',
      name: 'ckd',
      component: () => import('@/views/ckgl/ckd'),
      meta: { title: '出库单', icon: '点捕捉节点' }
    },
    {
      path: 'lhrw',
      name: 'lhrw',
      component: () => import('@/views/ckgl/lhrw'),
      meta: { title: '拣货任务', icon: '点捕捉节点' }
    },
    {
      path: 'jjrw',
      name: 'jjrw',
      component: () => import('@/views/ckgl/jjrw'),
      meta: { title: '交接任务', icon: '点捕捉节点' }
    }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// reset 路由方法
export function resetRouter() {
  // 得到一个全新的 router 实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher // reset router
}

export default router
